package org.geom.render;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class RenderManager {

	//-------------------------------------------------------- singleton
	private static RenderManager instance = null;
	private RenderManager() {
		
	}
	public static RenderManager getInstance() {
		if(instance==null)instance = new RenderManager();
		return instance;
	}
	
	//-------------------------------------------------------- render engine
	
	private Class<?> engine3Dclass;
	public void setEngine3D(Class<?> engine3Dclass) {
		this.engine3Dclass = engine3Dclass;
	}
	public IRenderer getEngine3D() {
		try {
			return (IRenderer) engine3Dclass.newInstance();
		} catch (InstantiationException e) {
			System.out.println("RenderManager > getEngine3D > EXCEPTION");
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			System.out.println("RenderManager > getEngine3D > EXCEPTION");
			e.printStackTrace();
		}
		return null;
	}

	private Class<?> engine2Dclass;
	public void setEngine2D(Class<?> engine2Dclass) {
		this.engine2Dclass = engine2Dclass;
	}
	public IRenderer getEngine2D(String plane) {
		try {
			Constructor<?> k = engine2Dclass.getConstructor(String.class);
			Object[] initargs = {plane};
			return (IRenderer) k.newInstance(initargs);
		} catch (InstantiationException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		} catch (SecurityException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			System.out.println("RenderManager > getEngine2D > EXCEPTION");
			e.printStackTrace();
		}
		return null;
	}

	
	

}

